package com.edu.exam.enums.assessment;

/**
 * 检查算法枚举
 */
public enum CheckAlgorithm {
    RULE_BASED("RULE_BASED", "基于规则"),
    PATTERN_MATCH("PATTERN_MATCH", "模式匹配"),
    STATISTICAL("STATISTICAL", "统计方法"),
    MACHINE_LEARNING("MACHINE_LEARNING", "机器学习"),
    SEMANTIC("SEMANTIC", "语义分析"),
    SYNTAX("SYNTAX", "语法分析"),
    LOGICAL("LOGICAL", "逻辑分析"),
    HYBRID("HYBRID", "混合算法"),
    CUSTOM("CUSTOM", "自定义算法");

    private final String code;
    private final String description;

    CheckAlgorithm(String code, String description) {
        this.code = code;
        this.description = description;
    }

    public String getCode() {
        return code;
    }

    public String getDescription() {
        return description;
    }

    public static CheckAlgorithm fromCode(String code) {
        if (code == null || code.trim().isEmpty()) {
            return RULE_BASED;
        }
        for (CheckAlgorithm algorithm : values()) {
            if (algorithm.getCode().equals(code)) {
                return algorithm;
            }
        }
        return RULE_BASED;
    }

    public static CheckAlgorithm fromDescription(String description) {
        if (description == null || description.trim().isEmpty()) {
            return RULE_BASED;
        }
        for (CheckAlgorithm algorithm : values()) {
            if (algorithm.getDescription().equals(description)) {
                return algorithm;
            }
        }
        return RULE_BASED;
    }

    @Override
    public String toString() {
        return this.code + "(" + this.description + ")";
    }
}